#include "No7pch.h"
#include "OpenGLBuffer.h"

#include <glad/glad.h>

nmspc::OpenGLVertexBuffer::~OpenGLVertexBuffer()
{
	glDeleteBuffers(1, &this->vertex_buffer_id);
}

nmspc::OpenGLVertexBuffer::OpenGLVertexBuffer(float* vertices, std::uint32_t size)
{
	glCreateBuffers(1, &this->vertex_buffer_id);
	glBindBuffer(GL_ARRAY_BUFFER, this->vertex_buffer_id);
	glBufferData(GL_ARRAY_BUFFER, size, vertices, GL_STATIC_DRAW);
}

void nmspc::OpenGLVertexBuffer::bind() const
{
	glBindBuffer(GL_ARRAY_BUFFER, this->vertex_buffer_id);
}

void nmspc::OpenGLVertexBuffer::unBind() const
{
	glBindBuffer(GL_ARRAY_BUFFER, 0);
}

nmspc::OpenGLIndexBuffer::~OpenGLIndexBuffer()
{
	glDeleteBuffers(1, &this->index_buffer_id);
}

nmspc::OpenGLIndexBuffer::OpenGLIndexBuffer(std::uint32_t* indices, std::uint32_t count) :
	count(count)
{
	glCreateBuffers(1, &this->index_buffer_id);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->index_buffer_id);
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, count * sizeof(std::uint32_t), indices, GL_STATIC_DRAW);
}

void nmspc::OpenGLIndexBuffer::bind() const
{
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, this->index_buffer_id);
}

void nmspc::OpenGLIndexBuffer::unBind() const
{
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}

std::uint32_t nmspc::OpenGLIndexBuffer::getCount() const
{
	return this->count;
}
